import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'logic.dart';

class UpdatePricesPage extends StatelessWidget {
  const UpdatePricesPage({super.key});

  @override
  Widget build(BuildContext context) {
    final logic = Get.put(UpdatePricesLogic());
    String data = Get.arguments ?? "默认"; // 获取传递的参数
    logic.getmsg(data);
    // config.apihttp.getmsg(data).then((onValue) {
    //   print(onValue);
    //   String msgTime = onValue['time'];
    //   double prices = double.parse(onValue['msg']);
    //
    //   logic.nowPrices.value = prices;
    //   logic.pricesUpdateTime.value = msgTime;
    // });
    return Scaffold(
      appBar: AppBar(
        title: Text(data),
      ),
      body: Column(
        children: [
          TextField(
            keyboardType: TextInputType.number,
            decoration: const InputDecoration(labelText: "输入"),
            maxLines: 1,
            controller: logic.pricesCtrl,
          ),
          Row(
            children: [
              Text(
                "目前价格:",
                style: logic.pricesTextStyle(),
              ),
              Obx(() {
                if (logic.nowPrices.value == 0.0) {
                  return const CircularProgressIndicator();
                } else {
                  return Text(
                    logic.nowPrices.value.toString(),
                    style: logic.pricesTextStyle(),
                  );
                }
              }),
            ],
          ),
          Row(
            children: [
              Text("时间：", style: logic.pricesTimeStyle()),
              Obx(() {
                return Text(
                  logic.pricesUpdateTime.value,
                  style: logic.pricesTimeStyle(),
                );
              }),
            ],
          ),
          TextButton(
            onPressed: () {
              String msg = logic.pricesCtrl.text;
              debugPrint("更新价格->$msg");
              logic.pushmsg(data, msg);
            },
            child: const Text("提交", style: TextStyle(fontSize: 32)),
          )
        ],
      ),
    );
  }
}
